package com.black.cat.bean;

import com.black.cat.config.BeanDefinition;
import com.black.cat.exception.BeansException;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * bean的注册和获取的所有功能，主要是对bean注册后的处理
 * @author 49504
 */
@Slf4j
public  class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements
        BeanDefinitionRegistry,ConfigurableListableBeanFactory {


    /** Map of bean definition objects, keyed by bean name */
    private final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<>(256);


    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeansException {
        this.beanDefinitionMap.put(beanName, beanDefinition);
    }

    @Override
    public boolean containsBeanDefinition(String beanName) {
        return this.beanDefinitionMap.containsKey(beanName);
    }

    @Override
    protected BeanDefinition getBeanDefinition(String beanName) throws BeansException {
        BeanDefinition bd = this.beanDefinitionMap.get(beanName);
        if (bd == null) {
            if (log.isTraceEnabled()) {
                log.trace("No bean named '" + beanName + "' found in " + this);
            }
  //          throw new BeansException(beanName);
        }
        return bd;
    }
}
